package org.pupil.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 拦截器工厂，责任链模式
 * @Author: pupil
 * @Date: 2024/07/17 下午 5:55
 */
public class FilterFactory {
    // 服务发送方前置拦截器链
    private static List<Filter> clientBeforeFilters = new ArrayList<>();
    // 服务发送方后置拦截器链
    private static List<Filter> clientAfterFilters = new ArrayList<>();
    // 服务提供方前置拦截器链
    private static List<Filter> serverBeforeFilters = new ArrayList<>();
    // 获取服务提供方后置拦截器链
    private static List<Filter> serverAfterFilters = new ArrayList<>();

    // 注册服务发送方前置拦截器
    public static void registerClientBeforeFilter(Filter filter) {
        clientBeforeFilters.add(filter);
    }

    // 注册服务发送方后置拦截器
    public static void registerClientAfterFilter(Filter filter) {
        clientAfterFilters.add(filter);
    }

    // 注册服务提供方前置拦截器
    public static void registerServerBeforeFilter(Filter filter) {
        serverBeforeFilters.add(filter);
    }

    // 注册服务提供方后置拦截器
    public static void registerServerAfterFilter(Filter filter) {
        serverAfterFilters.add(filter);
    }

    // 获取服务发送方前置拦截器链
    public static List<Filter> getClientBeforeFilters() {
        return clientBeforeFilters;
    }

    // 获取服务发送方后置拦截器链
    public static List<Filter> getClientAfterFilters() {
        return clientAfterFilters;
    }

    // 获取服务提供方前置拦截器链
    public static List<Filter> getServerBeforeFilters() {
        return serverBeforeFilters;
    }

    // 获取服务提供方后置拦截器链
    public static List<Filter> getServerAfterFilters() {
        return serverAfterFilters;
    }
}
